 <%@include file="/WEB-INF/common/taglibs.jsp"%>
<script type="text/javascript" src="${ctx}/resources/js/datatable-query.js"></script>
<div class="row-fluid">
	<div class="span12">
	<div class="box gradient">
	 
		<div class="title">
				<h4>
				<span>Album </span> <span class="box-form right"> </span>
				
				<span class="box-form right album_bar"><a href="#" class="btn btn-mini addAlbum">Add Album</a></span>
 				</h4>
 				<a href="#" class="minimize"> </a>
			</div>
		 <div class="content scrollable clearfix">
		<table class="table table-bordered table-vertical-centre albumTable">
			<thead>
				<tr>
					<th><a class="select_all"><span class="icomoon-icon-checkmark-2"></span></a></th>
<th>Name </th>
<th>Path </th>
<th>VisitPath </th>
<th>CreateTime </th>
<th>CreateDate </th>
<th>Category </th>
<th>Description </th>
<th>Cover </th>

 					<th>Action</th>
				</tr>
			</thead>
		</table>
		</div>
	 
</div>
 </div>
</div>




<script>
 
 

$(document).ready(function(){
	var del = {
			id : 'albumDel',
			text  : 'Del',
			domain : "Album",
			operation : "Del",
			url : "${ctx}/admin/album/del/",
			selector : ".album_bar",
			selects  : $('.albumTable'),
	  
	};
	johnny.tableBtn(del);
	
 	
	
	$('.addAlbum').click(function(){
	$("#albumDiv").find("div.modal-body").find("input,select,textarea,checkbox").not("[name=action],[type=hidden]").not("[type=radio]").each(function(step,value){
	 									$(value).val("");
	 							});
	
	
	
	 $("#albumDiv input[name='action']").val("${ctx}/admin/album/create/");
 	 $("#albumDiv").modal('show');
  });
	
	  $(document).delegate('.albumTable .icomoon-icon-pencil', 'click', function(event) {
		  
		  	var id = $(this).parent().attr("dataid");
			$.ajax({
				url : "${ctx}/admin/album/"+id+"/get/",
				type : "GET",
				dataType : "json",
				success : function(data){		
					if(data && data.state && (data.state.indexOf("ERROR") != -1)){
						johnny.error(data.message);
						return;
					}else{
							var entity = data.entity;
							
							
							
 							$("#albumDiv").find("div.modal-body").find("input,select,textarea,checkbox").not("[name=action],[type=hidden]").each(function(step,value){
									var name = $(value).attr("name");
									if ($(value).is(':radio')) {
										if (""+entity[name] ===""+$(value).val()){
  												$(value).attr("checked","checked");
   											}else{
   												$(value).removeAttr("checked");
 																			
 											}
										
									}else{
 									if (entity[name]|| entity[name]===0){
										$(value).val(entity[name]);
 										$(value).uniform();
 									}else if (name.match(/Id$/)){
										var pro = name.substring(0,name.length-2);
										if (entity[pro] &&entity[pro].id){
											$(value).val(entity[pro].id);
	 										$(value).uniform();
 										}
 									
									}
									else{
 										$(value).val("");
									}}
								
							});
							
							var x = $("#albumDiv").find("div.modal-body").find('input[type="radio"]').uniform();
   							$("#albumDiv input[name='action']").val("${ctx}/admin/album/"+id+"/edit/");
     	    				$("#albumDiv").modal('show');
 					}
				}
			});		  
 
	     
	    });
	var recordColumn = ['','name','path','visitPath','createTime','createDate','category','description','cover'];
	
	 $('.albumTable').dataTable({
		"bLengthChange" : true,
		"aoColumnDefs" : [ {
			'bSortable' : false,
			'aTargets' : [0 ]
		} ],
 		"sAjaxSource" : '${ctx}/admin/album/',
		"createQueryData" : function (aoData){
				return	johnny.initQueryData(aoData, recordColumn);
		},
		"createResult" : function (json, echo){
 			var dataArray = new Array();
			for ( var i = 0; i < json.result.length; i++) {
				var subArray = new Array();
				var value = johnny.getForSelect(json.result[i].id);
				subArray.push(value);
				subArray.push(json.result[i].name)
subArray.push(json.result[i].path)
subArray.push(json.result[i].visitPath)
subArray.push(json.result[i].createTime)
subArray.push(json.result[i].createDate)
if (json.result[i].category){
	subArray.push(json.result[i].category.name)
}else{
	subArray.push("")
}

subArray.push(json.result[i].description)
if (json.result[i].cover){
	subArray.push(coverHtml(json.result[i].cover));		
		}else{
		subArray.push("");
}
				var link = "${ctx}/admin/album/"+json.result[i].id+"/edit/";
   				var conf = [{
					link : 'javascript:void(1)',
					dataId : json.result[i].id,
					text : 'edit',
					css  : 'icomoon-icon-pencil'
				},
				{
					link : link,
					text : 'edit',
					css  : 'icomoon-icon-eyedropper'
				}
				
				];
				subArray.push(johnny.getGridLink(conf)); 
  				dataArray.push(subArray);
			}
			return {
				sEcho : echo,
				iTotalRecords : json.totalCount,
				iTotalDisplayRecords : json.totalCount,
				aaData : dataArray
			};
		}		
	});
	 
	
	
	
	
});

function coverHtml(obj){
	var mainSpan = $("<span>");
	var cover = $("<img>").attr({src:obj.visitThumb}).appendTo(mainSpan);

	return mainSpan.html();
	
}
</script>





<div id="albumDiv" class="modal hide fade"  selector=".albumTable" style="display: none; ">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal">
			<span class="icon12 minia-icon-close"></span>
		</button>
		<h3>	Album  </h3>
	</div>
 
	<div class="modal-body">
  						<input type="hidden" name="action" >
<!--name --><div class="form-row row-fluid"><div class="span12"><div class="row-fluid"><label class="form-label span3" for="name">Name :</label><input class="span9" id="name" name="name"   type="text" value="${entity.name}" /></div></div></div>
<!--createDate --><div class="form-row row-fluid"><div class="span12"><div class="row-fluid"><label class="form-label span3" for="createDate">CreateDate :</label><input class="span9 datepicker" id="createDate" name="createDate" type="text" value="<fmt:formatDate pattern="yyyy-MM-dd" value="${entity.createDate}" />" /></div></div></div>
<!--category --><div class="form-row row-fluid"><div class="span12"><div class="row-fluid"><label class="form-label span3">Category :</label><div class="span9 controls"><select name="categoryId"><c:if test="${not empty categories}"><c:forEach var="single" items="${categories}"><option value="${single.id}"${(single.id == entity.category.id)?'selected':'' }>${single.name}</option></c:forEach></c:if></select></div></div></div></div>
<!--description --><div class="form-row row-fluid"><div class="span12"><div class="row-fluid"><label class="form-label span3" for="description">Description :</label><input class="span9" id="description" name="description"   type="text" value="${entity.description}" /></div></div></div>

						 
	</div>
	 
	<div class="modal-footer">
		<a href="#" class="btn" data-dismiss="modal">Close</a>
		<a href="#" class="btn btn-primary modal-submit">Save changes</a>
	</div>

</div>


